package cn.laixueit.controller;

import cn.laixueit.pojo.Student;
import jdk.nashorn.internal.ir.ReturnNode;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;

import java.util.ArrayList;
import java.util.List;

//@Controller
@RestController
@RequestMapping("/student")
public class StudentController {

//    @RequestMapping("/index")
  /*  @GetMapping("/index")
    public String index(){
        System.out.println("index..");
        return "index";
    }

    @PostMapping("/save")
    public void save(){
        System.out.println("Save....");
    }

  *//*  @GetMapping("/findById")
    public String findById(@RequestParam(value = "cid",defaultValue = "0") Integer id){
        System.out.println("id..."+id);
        return "detail";
    }*//*

    @GetMapping("/requestHeader")
    public void requestHeader(@RequestHeader("User-Agent") String userAgent ){
        System.out.println(userAgent);
    }


    @GetMapping("/getById/{cid}/{id}")
    public void getById(@PathVariable("cid") Integer cid,@PathVariable("id")Integer id){
        System.out.println("cid.."+cid);
        System.out.println("id.."+id);
    }

    @ModelAttribute
    public void a(){
        System.out.println("a....");
    }*/

  /*  @GetMapping("/index")
    public String index(@ModelAttribute("msg") String msg){
        System.out.println(msg);
        return "index...";
    }*/

    @GetMapping("/index")
//    @ResponseBody
    public Student index(){
        Student student = new Student();
        student.setId(1);
        student.setName("zhangsan");
        return student;
    }

    @PostMapping("/save")
    public String save(@RequestBody Student student){
        System.out.println("student"+student);
        return "张三";
    }

    @GetMapping("/findAll")
    public List<Student> findAll(){
        ArrayList<Student> students = new ArrayList<>();
        for (int i = 0; i < 100; i++) {
            Student student = new Student();
            student.setId(i);
            student.setName("张三"+((char)(Math.random()*26+97))+"");
            students.add(student);
        }
        return  students;
    }
}
